package com.ymttest.database.sqlwapper;

import java.util.List;

import com.ymt.database.SqlManager;
import com.ymttest.database.model.YmtAppTuanMember;
import com.ymttest.utils.EnvSetup;

/**
 * 团成员sql
 * 
 * @author wanghuiyong
 * @date 2015-06-12
 */
public class YmtAppTuanMemberWapper {
	SqlManager manage;

	public YmtAppTuanMemberWapper() {
		manage = new SqlManager("ymt" + EnvSetup.getEnv());
	}

	/**
	 * 根据userid+groupcode查询是否参团
	 * 
	 * @return boolean
	 */
	public boolean getMemberGroupInfo(Integer UserId, String GroupCode) {
		YmtAppTuanMember member = new YmtAppTuanMember();
		member.setIuserid(UserId);
		member.setSgroupcode(GroupCode);
		List<YmtAppTuanMember> a = manage.getSelectResults(
				"com.ymttest.database.mapping.YmtAppTuanMemberMapper.selectByUserIdAndGroupCode", member);
		if (a.size() == 1) {
			return true;
		}
		return false;
	}

	/**
	 * 根据userid+groupcode删除参团信息
	 * 
	 * @return
	 */
	public boolean delTuanMember(Integer UserId, String GroupCode) {
		YmtAppTuanMember member = new YmtAppTuanMember();
		member.setIuserid(UserId);
		member.setSgroupcode(GroupCode);
		int a = manage.delete("com.ymttest.database.mapping.YmtAppTuanMemberMapper.deleteByUserIdAndGroupCode", member);
		manage.commit();
		if (a == 1) {
			return true;
		}
		return false;
	}

	/**
	 * 根据userid+groupcode删除参团信息
	 * 
	 * @return
	 */
	public boolean delTuanMember(Integer UserId) {
		YmtAppTuanMember member = new YmtAppTuanMember();
		member.setIuserid(UserId);
		int a = manage.delete("com.ymttest.database.mapping.YmtAppTuanMemberMapper.deleteByUserId", member);
		manage.commit();
		if (a == 1) {
			return true;
		}
		return false;
	}

	public static void main(String[] args) {
		YmtAppTuanMemberWapper test = new YmtAppTuanMemberWapper();
		// Logger.debug(test.delMember(1363619, "47298"));
		// Logger.debug(test.getMemberGroupInfo(1363619, "47298"));
	}
}
